<!DOCTYPE HTML>
<html lang="zh">
<head>
  @include('user.public.heads')
</head>
<body>
    @include('admin.public.navbar')
    <div style="margin-top: 100px;width:950px;margin-bottom: 20px;" class="container marketing">
        <div class="list-group">
            @foreach ($User as $key => $value)
            <a href="#" data-target="#Interlocution" data-toggle="modal" class="list-group-item" id={{ $value->id }}>{{ $value->name }}
            @if ($value->msg !== '0' && $value->for == config('setcheck.check'))
            <span class="badge">{{ $value->msg }}</span>
            @endif
            </a>
            @endforeach
        </div>

        <div style="display: block; margin-left: auto; margin-right: auto; text-align: center;">
        {!! $User->render() !!}
        </div>

    </div>
    @include('admin.public.foot')

    <div class="modal fade" id="Interlocution" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="myModalLabel">对话框</h4>
          </div>
          <div id="Interlocution-body" class="modal-body">
           
          </div>
          <hr>
           <input type="text" class="form-control" placeholder="说点啥?" id="str">
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            <button type="button" class="btn btn-primary" id="subtxt">Save</button>
          </div>
        </div>
      </div>
    </div>

</body>
</html>
<script type="text/javascript">
  var load= false;
  var html;
  var id;
  $('#Interlocution').on('show.bs.modal', function (e) {
    id = e.relatedTarget.id;
    html = '<iframe src="{{ url('Interlocution') }}?for='+e.relatedTarget.id+'" frameborder="0" scroling="yes" width="100%" id="iframe" ></iframe>'
    if(load != true){
      $('#Interlocution-body').append(html);
      $('#badge').text('');
      load = true;
    }
  });

  var body;
  var url;
  $("#subtxt").click(function(){
    body = $('#str').val();
    url = "{{ url('Interlocution') }}?for="+id;
    $.post(url, {body : body , _token : '{{ csrf_token() }}'}, function (data){
      if(data.status == 1){
        $('#str').val('');
        $('#iframe').attr('src', $('#iframe').attr('src'));
      }
    }, 'json');
  });

  $('#Interlocution').on('hidden.bs.modal', function (e) {
    $("#iframe").remove();
    $('#str').val('');
    load = false;
  });
</script>
